package com.knowif.backend.controller;

import com.github.pagehelper.PageInfo;
import com.knowif.backend.service.SettleParamService;
import com.knowif.pojo.SettleParam;
import com.knowif.pojo.SettleParamExample;
import com.knowif.search.SearchCondition;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Xh
 * @date ：Created in 2019/5/6 0006 20:07
 */
@RestController
@RequestMapping("/settleParam")
public class SettleParamController {

    @Autowired
    private SettleParamService settleParamService;

    @PostMapping("/query")
    public RestBean<?> query(@RequestBody SearchCondition searchCondition){
        try {
            SettleParamExample settleParamExample = (SettleParamExample) ExampleUtil.buildExample(new SettleParamExample(), searchCondition);
            List<SettleParam> settleParams = settleParamService.selectSettleParam(settleParamExample);
            PageInfo<SettleParam> pageInfo = new PageInfo<SettleParam>(settleParams);
            return new RestBean<>(RestBean.success_code, pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new RestBean<List<SettleParam>>(RestBean.bad_code, "参数错误");
    }

    @PostMapping("/update")
    public RestBean<?> update(@RequestBody SettleParam settleParam){
        if(settleParamService.updateSettleParamNotNull(settleParam)){
            return new RestBean<Object>(RestBean.success_code);
        }
        return new RestBean<Object>(RestBean.bad_code, "添加失败");
    }

}